<template>
  <div
    :class="['config', { right_hide: !show }]"
    :style="`width:${toolbarWidth}px`"
  >
    <ConfigGrid v-show="type === 'grid'" />
    <ConfigNode :id="id" v-show="type === 'node'" />
    <ConfigEdge :id="id" v-show="type === 'edge'" />
    <FoldBtn direction="right" v-model:show="show" />
  </div>
</template>

<script lang="ts">
import { toolbarWidth } from '@/config/index'
import FoldBtn from '@/components/FoldBtn.vue'
import ConfigGrid from './ConfigGrid.vue'
import ConfigNode from './ConfigNode.vue'
import ConfigEdge from './ConfigEdge.vue'
import { FlowGraph } from '@/common/FlowGraph'
import { defineComponent, ref } from 'vue'

export default defineComponent({
  name: 'index',
  components: {
    ConfigGrid,
    ConfigNode,
    ConfigEdge,
    FoldBtn
  },
  setup() {
    const type = ref('grid')
    const id = ref('')
    const { graph } = FlowGraph
    graph.on('blank:click', () => {
      type.value = 'grid'
    })
    graph.on('cell:click', ({ cell }) => {
      type.value = cell.isNode() ? 'node' : 'edge'
      id.value = cell.id
    })
    return {
      type,
      id,
      show: ref(true),
      toolbarWidth: ref(toolbarWidth)
    }
  }
})
</script>

<style lang="less" scoped>
.config {
  height: calc(100% - 40px);
  padding: 0 10px;
  position: absolute;
  top: 40px;
  right: 0;
  z-index: 100;
  transition: 0.4s;
  background-color: #fff;
  box-sizing: border-box;
  border-left: 1px solid #d9d9d9;
}

.right_hide {
  right: -280px;
  transition: 0.4s;
}
</style>
